package com.example.sztangli.widgedemo.base;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.example.sztangli.widgedemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by sztangli on 2017/7/13.
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected Unbinder mUnbinder;
    protected AppApplication mApplication;
    protected FragmentManager mFragmentManager;

    @BindView(R.id.title_center)
   protected TextView titleCenter;
    @BindView(R.id.toolbar)
   protected Toolbar toolbar;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        mApplication=(AppApplication) getApplication();
        mFragmentManager=getSupportFragmentManager();
        mUnbinder= ButterKnife.bind(this);
        initToolBar();
        initalFragment();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mUnbinder!=null){
            mUnbinder.unbind();
            mUnbinder=null;
        }
    }

    protected void initToolBar(){
        toolbar.setNavigationIcon(R.mipmap.back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public View getRootView(){
        return findViewById(R.id.container);
    }

    public void setTitleCenter(String title){
        titleCenter.setText(title);
    }

    public abstract int getLayoutResId();

    public abstract void initalFragment();
}
